
//=======================================
// TABLE A3
//=======================================


local policy_date=14943							//policy change date in days 
local citation_window=3650						//max priority-priority lag
local window_size=7								//size of time window for repeated cross-sectional analysis
local window_num=26							//number of times windows either side of policy change
local window=`window_num'*`window_size'			//resulting cohort window size						

global DATA  "path/to/input/data"   
global OUT "path/to/output/folder"
global INT "path/to/intermediate/files"

local controls_fes="i.time science_cites originality inventors_citing i.wipo_citing_broad i.wipo_cited_broad"

est clear 
*take base set
use "$DATA\twincites_applicant_did_prep.dta", clear

*apply special restrictions for this analysis (as baseline, check if control variables are nonmissing)

drop if backcite_count_citing>100

*drop citations from PCT applications

rename family_citing docdb_family_id
merge m:1 docdb_family_id using "$DATA\pctfamlist.dta", nogen keep(match master)
rename docdb_family_id family_citing 
drop if pct==1

* drop all but first citation from each geographical source for each family
sort family_cited priority_citing_d
duplicates drop family_cited nonJP, force

*remove families that only had citations from one source

duplicates tag family_cited, gen(tag)
drop if tag==0
drop tag

*set up time parameter
gen temp=floor((US_filing_date_d_cited-`policy_date')/`window_size')
quietly: sum temp
gen time=temp-r(min)

eststo: xi: reg lag treated nonJP `controls_fes', vce(cluster inventor_country_citing_e)
esttab using "$OUT\baseline_did_nopct.tex", replace ///
b(3) p(3) nomtitle nonote label booktabs f star(* 0.10 ** 0.05 *** 0.01) ///
keep(treated nonJP science_cites originality inventors_citing _cons) ///
mlabel("All" "$\leq 100$" "$\leq 50$" "$\leq 20$") indicate("Time FEs = _Itime_*" "Citing field FEs = _Iwipo_citi*" "Cited field FEs = _Iwipo_cite*") alignment(D{.}{.}{-1})

didregress (lag science_cites originality inventors_citing i.wipo_citing_broad i.wipo_cited_broad) (treated), group(inventor_country_citing_e) time(time)
estat ptrends

